﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Account.Model;
using Yipusoft.Account.BLL;
using Yipusoft.Vehicle.BLL;
using System.Data;

public partial class BasicBase_Vehicle_DriversView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            init();
        }
    }

    void init()
    {
        BindDepartment();
        BindGV(0);
    }

    void BindDepartment()
    {
        string where = " DepartmentId like '%000' and DepartmentId <>'1300000' ";
        List<DepartmentInfo> list = Department.GetList(where);
        DepartmentList.DataSource = list;
        DepartmentList.DataBind();

    }
    void BindGV(int pageIndex)
    {
        string where = " (DepartmentID LIKE '" + DepartmentList.SelectedValue.Substring(0, 4) + "%')";
        DataTable dt = VehicleDriver.GetVWDriversList(where, pageIndex, ListPageContral1.PageSize);
        ListPageContral1.ItemCount = dt.Rows.Count;
        gvSoldiers.DataSource = dt;
        gvSoldiers.DataBind();

    }

    protected void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        BindGV(PageIndex);
    }

    protected void gvSoldiers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = Convert.ToString(gvSoldiers.PageSize * ListPageContral1.CurrentPageIndex + (e.Row.RowIndex + 1));

            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");

            DataRowView dr = e.Row.DataItem as DataRowView;
            System.Web.UI.HtmlControls.HtmlAnchor AName = e.Row.FindControl("AName") as System.Web.UI.HtmlControls.HtmlAnchor;

            //----------士兵查看--------------------------------------------------------

            if (Convert.ToInt32(dr["IsContract"]) == 1)
            {
                //AName.HRef = "javascript:OpenWin('EmployeeView.aspx?ID=" + soldier.SoldierID + "')";

                AName.HRef = "../SoldierArchive/EmployeeView.aspx?ID=" + dr["SoldierID"];

            }
            else
            {
                //AName.HRef = "javascript:OpenWin('SoldierView1.aspx?ID=" + soldier.SoldierID + "')";
                AName.HRef = "../SoldierArchive/SoldierView1.aspx?ID=" + dr["SoldierID"];

            }

            Label DepartmentName = e.Row.FindControl("DepartmentName") as Label;
            DepartmentInfo department = Department.GetDepartment(dr["DepartmentId"].ToString());
            if (department != null)
            {
                DepartmentName.Text = department.ShortName;

            }
            else
            {
                DepartmentName.Text = "----";
            }
            HyperLink HypVehicle = e.Row.FindControl("HypVehicle") as HyperLink;
            HypVehicle.NavigateUrl = "VehicleView.aspx?id=" + dr["VehicleId"];
            Label lblVehicleType = e.Row.FindControl("lblVehicleType") as Label;

            lblVehicleType.Text = GetClass(dr["VehicleClass"].ToString());
        }
    }

    public string GetCodeItem(string GroupID, string deviceClass)
    {
        Yipusoft.Common.Model.CodeItemInfo info = Yipusoft.Common.BLL.CodeItem.GetCodeItem(deviceClass, GroupID);
        return info != null ? info.ItemName : "";
    }

    protected void DepartmentList_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindGV(0);
    }

    public string GetClass(string classID)
    {
        Yipusoft.Common.Model.CodeItemInfo info = Yipusoft.Common.BLL.CodeItem.GetCodeItem(classID, "XFZBLB");
        if (info != null)
        {
            return info.ItemName;
        }
        else
        {
            info = Yipusoft.Common.BLL.CodeItem.GetCodeItem(classID);
            if (info != null)
            {
                return info.ItemName;
            }
            else
            {
                return "";
            }
        }
    }
}
